﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FSY.API.Utilities;
using FSY.Components.Entities;
namespace FSY.Web.Admin.Portals
{
    public partial class EditPortal : System.Web.UI.UserControl
    {
        #region Variable
        private static Fsy_Portal portal;
        #endregion

        #region Event
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                FillFormEdit();
            }
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            UpdateItem();
            Response.Redirect("Default.aspx?tabid=2&obj=portal");
        }
        #endregion

        #region Function
        private void FillFormEdit()
        {
            if (Request.QueryString["id"] != null)
            {
                int portalID = Fsy_Null.SetNullInteger(Request.QueryString["id"]);
                if (Fsy_PortalController.IsExist(portalID))
                {
                    portal = Fsy_PortalController.GetPortalByID;
                    txtPortalName.Text = portal.PortalName;
                    txtDescription.Text = portal.Discription;
                    lblCreatedBy.Text = portal.CreatedByUserName;
                    lblModifiedBy.Text = Session["UserName"].ToString();
                }
            }
        }

        private void UpdateItem()
        {
            portal.PortalName = this.txtPortalName.Text;
            portal.Discription = Server.HtmlEncode(this.txtDescription.Text);
            portal.LastModifiedByUserID = Fsy_Null.SetNullInteger(Session["UserID"].ToString());
            portal.LastModifiedOnDate = DateTime.Now;
            Fsy_PortalController.Update(portal);
        }
        #endregion       
    }
}